package com.gjy.controller;

import com.gjy.domain.Student;
import com.gjy.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/stu")
public class StudentController {

    @Autowired
    StudentService studentService;

    @RequestMapping(value = "/stuLogin",method = RequestMethod.POST)
    public String stuLogin(@RequestParam("stuId") String name, @RequestParam("stuPassword") String password){
        List<Student> all = studentService.findAll();
        if (!name.isEmpty()){
            int i = Integer.parseInt(name);
            for (Student student : all) {
                if (student.getId().equals(i) && student.getPassword().equals(password)) {
                    return "student";
                }
            }
        }
        return "error";
    }
}
